package com.lingz.manager.modules.wuxue.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingz.manager.common.vo.PageVo;
import com.lingz.manager.modules.wuxue.mapper.DailyInsectCatchDataMapper;
import com.lingz.manager.modules.wuxue.entity.DailyInsectCatchData;
import com.lingz.manager.modules.wuxue.service.DailyInsectCatchDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 纽康每日捕虫数数据接口实现
 * @author caiyixun
 */
@Slf4j
@Service
@Transactional
public class DailyInsectCatchDataServiceImpl extends ServiceImpl<DailyInsectCatchDataMapper, DailyInsectCatchData> implements DailyInsectCatchDataService {

    @Autowired
    private DailyInsectCatchDataMapper dailyInsectCatchDataMapper;

    @Override
    public List<DailyInsectCatchData> findListDailyInsectCatchData(DailyInsectCatchData dailyInsectCatchData){
        LambdaQueryWrapper<DailyInsectCatchData> wrapper = Wrappers.lambdaQuery(DailyInsectCatchData.class);
        List<DailyInsectCatchData> list = dailyInsectCatchDataMapper.selectList(wrapper);
        return list;
    }

    @Override
    public Page<DailyInsectCatchData> findPageDailyInsectCatchData(DailyInsectCatchData dailyInsectCatchData,PageVo pageVo){
        // 当前页数
        int pageNumber = pageVo.getPageNumber();
        // 每页显示的条数
        int pageSize = pageVo.getPageSize();

        LambdaQueryWrapper<DailyInsectCatchData> wrapper = Wrappers.lambdaQuery(DailyInsectCatchData.class);
        Page<DailyInsectCatchData> pageList = dailyInsectCatchDataMapper.selectPage(new Page<>(pageNumber, pageSize),wrapper);
        return pageList;
    }

    @Override
    public String addDailyInsectCatchData(DailyInsectCatchData dailyInsectCatchData){
        dailyInsectCatchDataMapper.insert(dailyInsectCatchData);
        return "操作成功";
    }

    @Override
    public String editDailyInsectCatchData(DailyInsectCatchData dailyInsectCatchData){
        dailyInsectCatchDataMapper.updateById(dailyInsectCatchData);
        return "操作成功";
    }

    @Override
    public String deleteDailyInsectCatchData(String[] ids){
        dailyInsectCatchDataMapper.deleteBatchIds(Arrays.asList(ids.clone()));
        return "操作成功";
    }

    @Override
    public DailyInsectCatchData findDailyInsectCatchDataById(String id) {
        return baseMapper.selectById(id);
    }
}